//
//  FileDownloader.m
//  DownloadManager
//
//  Created by Deepak Kumar on 12/03/12.
//  Copyright 2012 Frog. All rights reserved.
//

#import "FileDownloader.h"


@implementation FileDownloader
@synthesize mIndexPath, mPhoto, mDelegate;

- (void)startDownloadWithFileURL:(NSString *)pURL
{
    NSLog(@"startDownloadWithFileURL:%@", pURL);

	[NSThread detachNewThreadSelector:@selector(downloadImageURL:) toTarget:self withObject:pURL];		
}

	

- (void) downloadImageURL:(NSString *)pURL
{
	@autoreleasepool {
		mPhoto.mImage = [UIImage imageWithContentsOfFile:pURL];
		
		[self performSelectorOnMainThread:@selector(callDelegteMethod) withObject:nil waitUntilDone:YES];

	}
}

- (void) callDelegteMethod
{
	if ([self.mDelegate respondsToSelector:@selector(fileDownloader:photo:indexPath:)]) {
		
		// call our delegate and tell it that our icon is ready for display
		[mDelegate fileDownloader:self photo:mPhoto indexPath:mIndexPath];
	}    
}



@end
